package com.chenl.provider.util;


import com.chenl.provider.DTO.vo.EmailSendDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class EmailSendService {
    @Value("${spring.mail.username}")
    private String email;

    @Autowired
    JavaMailSender javaMailSender;

    /**
     * 发送邮件 所需参数 标题/邮件内容/邮件接收方邮箱
     *
     * @param emailSendDto
     */
    public void sendMail(EmailSendDto emailSendDto) {
        long l = System.currentTimeMillis();
        SimpleMailMessage message = new SimpleMailMessage();
        //设置邮件标题
        message.setSubject(emailSendDto.getEmailTitle());
        //设置发送方
        message.setFrom(email);
        message.setSentDate(new Date());
        //设置邮件内容
        message.setText(emailSendDto.getSendMsg());
        //设置接收方
        message.setTo(emailSendDto.getAcceptor());
        javaMailSender.send(message);
        System.out.println("时间" + (l - System.currentTimeMillis()));
    }
}